﻿#include <libcomm.h>

void __SignalHandler(int signo) 
{
	printf("SIGNAL(%d) interrupt !\n",signo);
	printf("%s",StackTracer::TraceStack().get());
	exit(0);
}

int num = 0;
class MyThreadPool : public ThreadPool
{
public:
	ThreadFreeLock locker;
	MyThreadPool() :ThreadPool(100) {}
	virtual int Process(int index)
	{
		ThreadLockGuard guard1(&locker);
		{
			ThreadLockGuard guard2(&locker);
			{
				ThreadLockGuard guard3(&locker);
				num++;
				//Thread::Sleep(1);
			}
			
		}
		
		return 0;
	}
};


int main(int argc, char *argv[])
{
	Singleton<Log>::Instance()->SetLogger(new Log::SilenceLogger());
#ifndef COMM_MSVC
	struct sigaction act;
	act.sa_handler = __SignalHandler;
	MYLIB_ASSERT_ERRNO(0==sigfillset(&act.sa_mask));//forbid all signal while handler.
	act.sa_flags = 0;
	//MYLIB_ASSERT_ERRNO(0==sigaction(SIGINT,&act,NULL));
	MYLIB_ASSERT_ERRNO(0==sigaction(SIGSEGV,&act,NULL));
	MYLIB_ASSERT_ERRNO(0==sigaction(SIGILL,&act,NULL));
	MYLIB_ASSERT_ERRNO(0==sigaction(SIGFPE,&act,NULL));
	MYLIB_ASSERT_ERRNO(0==sigaction(SIGTERM,&act,NULL));
	MYLIB_ASSERT_ERRNO(0==sigaction(SIGABRT,&act,NULL));
	//signal(SIGUSR1,SIG_IGN);
#endif

	LOGDEBUG("COMLIB: %s",common_version());

	Timer timer;
	MyThreadPool pool;
	timer.Start();
	{
		pool.Start();
		pool.Stop();
	}
	timer.Stop();
	printf("num: %d; elapse: %d.\n", num, timer.Elapse() / 1000);
	//getchar();
	return 0;
}
